﻿using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for CheckAssignment.xaml which is the window showing information about an assignment.
    /// </summary>
    public partial class CheckAssignment : Window
    {
        public string AssignmentText;
        public int AssignmentInt;
        private List<element> answers;
        private List<bogus> bogusAnswers;
        public List<String> Answervalue;
        public List<String> BogusAnswerValue;

        public CheckAssignment()
        {
            Answervalue = new List<string>();
            BogusAnswerValue = new List<string>();
            InitializeComponent();
        }

        /// <summary>
        /// Gets all the assignment information from the database and adds it to the different controllers
        /// </summary>
        public void setInfo()
        {
            Title = Queries.GetAssignment(AssignmentInt).assName;
            AssignmentText = Queries.GetAssignment(AssignmentInt).text;
            answers = Queries.GetElements(AssignmentInt);
            foreach(element e in answers)
            {
                Answervalue.Add(e.element1);
            }
            comboBox1.ItemsSource = Answervalue;
            textBox1.Text = AssignmentText;
        }

        /// <summary>
        /// Eventlistener looking at comboBox1 and updating the inventory of comboBox2 when the selection is changed
        /// </summary>
        private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            BogusAnswerValue.Clear();
            if(comboBox1.SelectedIndex >= 0)
            {
                int id = answers[comboBox1.SelectedIndex].id;
                bogusAnswers = Queries.GetBogus(id);
                foreach (bogus b in bogusAnswers)
                {
                    BogusAnswerValue.Add(b.element);
                }
                comboBox2.ItemsSource = BogusAnswerValue;
                comboBox2.Items.Refresh();
            }
        }

        /// <summary>
        /// Event listener on the help button, creating a message box
        /// </summary>
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("Dette vindue fortæller dig hvad opgaveteksten i den valgte opgave er." +
                            System.Environment.NewLine
                            + System.Environment.NewLine +
                            "Den første af de 2 lister viser hvilke rigtige svar der er i opgaven, rækkefølgen passer til rækkefølgen de forventes i teksten" +
                            System.Environment.NewLine + System.Environment.NewLine +
                            "Den anden liste viser hvilke andre svar eleven får som mulighed til svaret valgt i første liste");
        }
    }
}
